libobs_wrapper\data\properties/
prop_impl.rs

1use crate::{
2    data::output::ObsOutputRef,
3    runtime::ObsRuntime,
4    sources::ObsSourceRef,
5    unsafe_send::Sendable,
6    utils::{ObsError, ObsString},
7};
8
9use super::{get_properties_inner, ObsProperty, ObsPropertyObject, ObsPropertyObjectPrivate};
10
11#[cfg_attr(not(feature = "blocking"), async_trait::async_trait)]
12impl ObsPropertyObject for ObsSourceRef {
13    #[cfg_attr(feature = "blocking", remove_async_await::remove_async_await)]
14    async fn get_properties(&self) -> Result<Vec<ObsProperty>, ObsError> {
15        let properties_raw = self.get_properties_raw().await?;
16        get_properties_inner(properties_raw, self.runtime.clone()).await
17    }
18}
19
20#[cfg_attr(not(feature = "blocking"), async_trait::async_trait)]
21impl ObsPropertyObjectPrivate for ObsSourceRef {
22    #[cfg_attr(feature = "blocking", remove_async_await::remove_async_await)]
23    async fn get_properties_raw(
24        &self,
25    ) -> Result<Sendable<*mut libobs::obs_properties_t>, ObsError> {
26        let source_ptr = self.source.clone();
27        self.runtime
28            .run_with_obs_result(move || unsafe {
29                let source_ptr = source_ptr;
30
31                Sendable(libobs::obs_source_properties(source_ptr.0))
32            })
33            .await
34            .map_err(|e| ObsError::InvocationError(e.to_string()))
35    }
36    #[cfg_attr(feature = "blocking", remove_async_await::remove_async_await)]
37    async fn get_properties_by_id_raw<T: Into<ObsString> + Sync + Send>(
38        id: T,
39        runtime: ObsRuntime,
40    ) -> Result<Sendable<*mut libobs::obs_properties_t>, ObsError> {
41        let id: ObsString = id.into();
42        let id_ptr = id.as_ptr();
43        runtime
44            .run_with_obs_result(move || unsafe {
45                let id_ptr = id_ptr;
46                Sendable(libobs::obs_get_source_properties(id_ptr.0))
47            })
48            .await
49            .map_err(|e| ObsError::InvocationError(e.to_string()))
50    }
51}
52
53#[cfg_attr(not(feature = "blocking"), async_trait::async_trait)]
54impl ObsPropertyObject for ObsOutputRef {
55    #[cfg_attr(feature = "blocking", remove_async_await::remove_async_await)]
56    async fn get_properties(&self) -> Result<Vec<ObsProperty>, ObsError> {
57        let properties_raw = self.get_properties_raw().await?;
58        get_properties_inner(properties_raw, self.runtime.clone()).await
59    }
60}
61
62#[cfg_attr(not(feature = "blocking"), async_trait::async_trait)]
63impl ObsPropertyObjectPrivate for ObsOutputRef {
64    #[cfg_attr(feature = "blocking", remove_async_await::remove_async_await)]
65    async fn get_properties_raw(
66        &self,
67    ) -> Result<Sendable<*mut libobs::obs_properties_t>, ObsError> {
68        let output_ptr = self.output.clone();
69        self.runtime
70            .run_with_obs_result(move || unsafe {
71                let output_ptr = output_ptr;
72
73                Sendable(libobs::obs_output_properties(output_ptr.0))
74            })
75            .await
76            .map_err(|e| ObsError::InvocationError(e.to_string()))
77    }
78
79    #[cfg_attr(feature = "blocking", remove_async_await::remove_async_await)]
80    async fn get_properties_by_id_raw<T: Into<ObsString> + Sync + Send>(
81        id: T,
82        runtime: ObsRuntime,
83    ) -> Result<Sendable<*mut libobs::obs_properties_t>, ObsError> {
84        let id: ObsString = id.into();
85        let id_ptr = id.as_ptr();
86        runtime
87            .run_with_obs_result(move || unsafe {
88                let id_ptr = id_ptr;
89
90                Sendable(libobs::obs_get_output_properties(id_ptr.0))
91            })
92            .await
93            .map_err(|e| ObsError::InvocationError(e.to_string()))
94    }
95}